/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：TriggerEffect.java <br>
 * 创建时间：2015-3-7 下午12:41:45 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.data;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.blgframework.CScreen;
import lostland.gmud.exv2.ui.SimpleNotificationScreen;
import lostland.gmud.exv2.ui.TalkingScreen;
import lostland.gmud.exv2.ui.TradeScreen;
import lostland.gmud.exv2.ui.core.YesNoScreen;

/**
 * 类名：TriggerEffect <br>
 * 说明：
 *
 * @author 12548
 */
public class TriggerEffect {

	public int effectID = 0;

	public boolean boolArg = false;
	public int intArg1 = 0;
	public int intArg2 = 0;
	public int intArg3 = 0;
	public int intArg4 = 0;
	public float floatArg = 0f;
	public String strArg = "";

	public boolean useParentArgs = false;


	/**
	 * 注释，无实际用处。
	 */
	public static final int EFFECT_COMMENT = 0;

	/**
	 * 无条件跳转到行号为整数参数1的行。如果跳转的行号小于0或大于最大行数，都会立即终结整个触发事件。
	 */
	public static final int EFFECT_GOTO = 1;

	/**
	 * 如果满足编号为整数参数2的条件，则跳转到编号为整数参数1的行。
	 */
	public static final int EFFECT_CONDITION_GOTO = 2;

	/**
	 * 堆栈编号为整数参数3的触发（可以递归），从编号为整数参数4的行开始执行。其他参数会传到目标触发事件中。
	 */
	public static final int EFFECT_CALL_TRIGGER = 3;


	/**
	 * 向玩家询问是/否，是则继续执行下一行，否则跳转到编号为整数参数1的行。
	 */
	public static final int EFFECT_YESNO = 4;

	public static final int EFFECT_SHOW_DIALOG = 5;

	public static final int EFFECT_SHOW_NOTIFICATION = 6;

	/**
	 * 向编号为整数参数1的NPC请教，文字提示为字符串参数。
	 */
	public static final int EFFECT_LEARN_TO_NPC = 7;

	/**
	 * 设置编号为整数参数1的NPC的整数参数2号属性为整数参数3。如果整数参数1小于0，则设置主角的属性。
	 */
	public static final int EFFECT_SET_NPC_ATTR = 8;

	public static final int EFFECT_SET_NPC_ATTR_VAR = 9;

	public static final int EFFECT_SET_NPC_ATTR_TEMP_VAR = 10;

	/**
	 * 设置编号为整数参数1的NPC的整数参数2号技能等级，保存到编号为整数参数3的临时变量。如果整数参数1小于0，则设置主角的属性。
	 */
	public static final int EFFECT_GET_NPC_SKILL_LVL = 11;

	/**
	 * 执行触发效果。
	 *
	 * @return 执行后跳转到的行号。
	 */
	public int exec(boolean _boolArg, int _intArg1, int _intArg2, float _floatArg, String _strArg, final int _currentLine) {
		if (effectID <= EFFECT_COMMENT) return _currentLine + 1;

		if (useParentArgs) {
			boolArg = _boolArg;
			intArg1 = _intArg1;
			intArg2 = _intArg2;
			floatArg = _floatArg;
			strArg = _strArg;
		}

		switch (effectID) {
			case EFFECT_GOTO:
				return intArg1;
			case EFFECT_CONDITION_GOTO:
				if (Gmud.conditions.get(intArg2).check()) return intArg1;
				break;
			case EFFECT_CALL_TRIGGER:
				Game.getInstance().callTriggerEvent(intArg3, boolArg, intArg1, intArg2, floatArg, strArg, intArg4);
				break;
			case EFFECT_YESNO: {
				CScreen scrn = new YesNoScreen(strArg) {

					@Override
					protected void onYes() {
						int line = _currentLine + 1;
						if (getGame().getParentScreen() instanceof TriggerScreen) {
							TriggerScreen ts = (TriggerScreen) getGame().getParentScreen();
							ts.currentLine = line;
						}
						getGame().popScreen();
					}

					@Override
					protected void onNo() {
						int line = intArg1;
						if (getGame().getParentScreen() instanceof TriggerScreen) {
							TriggerScreen ts = (TriggerScreen) getGame().getParentScreen();
							ts.currentLine = line;
						}
						getGame().popScreen();
					}
				};
				scrn.pushToGame();
			}
			break;
			case EFFECT_SHOW_DIALOG:
				new TalkingScreen(strArg).pushToGame();
				break;
			case EFFECT_SHOW_NOTIFICATION:
				new SimpleNotificationScreen(strArg).pushToGame();
				break;
			case EFFECT_LEARN_TO_NPC:
				new TradeScreen(intArg1, 102, strArg).pushToGame();
				break;
			case EFFECT_SET_NPC_ATTR: {
				Npc npc = Gmud.mc;
				if (intArg1 >= 0)
					npc = Gmud.getNpc(intArg1);

				npc.setAttr(intArg2, intArg3);
			}
			break;
			case EFFECT_SET_NPC_ATTR_VAR: {
				Npc npc = Gmud.mc;
				if (intArg1 >= 0)
					npc = Gmud.getNpc(intArg1);

				npc.setAttr(intArg2, Game.getData().game_variavble.get(intArg3));
			}
			break;
			case EFFECT_SET_NPC_ATTR_TEMP_VAR: {
				Npc npc = Gmud.mc;
				if (intArg1 >= 0)
					npc = Gmud.getNpc(intArg1);

				npc.setAttr(intArg2, Gmud.temp_variavble.get(intArg3));
			}
			break;
		}

		return _currentLine + 1;

	}
}
